DINERO='./PC_dinero'
BUS2='./read'
COMPU='./control'
RESULT_PRE="./res"
RESULT_SUFFIX=".txt"
RESULT_BUS2="./bus2-"
CACHE_SETTINGS="a b c"
DATA_FILES="1 2"
DATAFILE1="./lisp.002.din"
DATAFILE2="./spic.002.din"

DINERO_ARGS_a="-b1 -u1"
DINERO_ARGS_b="-b128 -a1 -ww -An -u64k"
DINERO_ARGS_c="-b128 -a1 -wc -Aw -u64k"

if [ ! -x $DINERO ]; then
    echo "$DINERO binary not found" 1>&2
    echo "Please alter $0 to specifify right constants" 1>&2
    exit 128;
fi

if [ ! -r $DATAFILE ]; then
    echo "$DATAFILE file not found" 1>&2
    echo "Please alter $0 to specifify right constants or" 1>&2
    echo "Usage $0 <datafile>" 1>&2
    exit 128;
fi

make clean
make


for data_file in $DATA_FILES
do
eval DATAFILE=\$DATAFILE$data_file
echo "Using datafile $DATAFILE$data_file" 1>&2
    for cache_setting in $CACHE_SETTINGS
    do
        (
        eval DINERO_ARGS=\$DINERO_ARGS_$cache_setting
        echo "==============================================="
	echo ""
        echo "Generated      : `date`"
        echo "Input data     : $DATAFILE$data_file"
        echo "Cache setting  : $DINERO_ARGS_$cache_setting"
        echo "Dinero args    : $DINERO_ARGS"
	echo ""
        cat $DATAFILE | $DINERO -o2 $DINERO_ARGS |\
        $BUS2 |\
        tee -i $RESULT_BUS2$cache_setting$RESULT_SUFFIX |\
        $COMPU
        echo "==============================================="
        ) | tee -a -i $RESULT_PRE$RESULT_SUFFIX 1>&2
    done
    if [ $data_file == 1 ]; then
	(
	echo ""
	echo "++++++++++++++++ NEW DATA FILE ++++++++++++++++"
	echo ""
	) | tee -a -i $RESULT_PRE$RESULT_SUFFIX 1>&2
    fi
done

